package com.kezesong.leasing.controller;


import com.kezesong.leasing.common.ResponseResult;
import com.kezesong.leasing.controller.response.GoodsCategoryListRspBody;
import com.kezesong.leasing.controller.response.GoodsDetailsRspBody;
import com.kezesong.leasing.controller.response.GoodsListRspBody;
import com.kezesong.leasing.service.GoodsCategoryService;
import com.kezesong.leasing.service.GoodsInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/page")
public class GoodsInfoController extends BaseController{

    @Autowired
    private GoodsCategoryService goodsCategoryService;

    @Autowired
    private GoodsInfoService goodsInfoService;


    @GetMapping("/getCategoryList.do")
    @ApiOperation(value = "getCategoryList", notes = "获取全部商铺类别列表")
    public ResponseResult<List<GoodsCategoryListRspBody>> getShopList(){
        List<GoodsCategoryListRspBody> goodsCategoryShowList = goodsCategoryService.getGoodsCategoryShowList();
        ResponseResult<List<GoodsCategoryListRspBody>> listResponseResult = buildSucessResponse(goodsCategoryShowList);
        return listResponseResult;
    }


    @GetMapping("/getGoodsInfoShowList/{categoryId}/{pageSize}/{pageIndex}")
    @ApiOperation(value = "getGoodsInfoShowList", notes = "获取商品展示列表")
    public ResponseResult<List<GoodsListRspBody>> getGoodsInfoShowList(@PathVariable("categoryId") int categoryId,
                                                                       @PathVariable("pageSize") int pageSize,
                                                                       @PathVariable("pageIndex") int pageIndex){
        List<GoodsListRspBody> goodsInfoShowRspList = goodsInfoService.getGoodsInfoShowRspList(categoryId,pageSize,pageIndex);

        if (null == goodsInfoShowRspList || goodsInfoShowRspList.size() == 0){
            return buildNoDataResponse();
        }else{
            ResponseResult<List<GoodsListRspBody>> listResponseResult = buildSucessResponse(goodsInfoShowRspList);
            return listResponseResult;
        }
    }


    @GetMapping("/getGoodsInfoDetails/{goodsId}")
    @ApiOperation(value = "getGoodsInfoDetails", notes = "获取商品详情")
    public ResponseResult<GoodsDetailsRspBody> getGoodsInfoDetails(@PathVariable("goodsId") int goodsId){
        GoodsDetailsRspBody goodsDetailsRspBody = goodsInfoService.getGoodsDetails(goodsId);
        if (null == goodsDetailsRspBody){
            return buildNoDataResponse();
        }else{
            ResponseResult<GoodsDetailsRspBody> responseResult = buildSucessResponse(goodsDetailsRspBody);
            return responseResult;
        }
    }





}
